package com.gopay.bis.manager.bank.bcdl;
import java.util.Map;
import javax.annotation.Resource;
import com.gopay.common.domain.bank.cmb.ebank.queryNtnstqry.CmbDownLoadMessage;
import org.springframework.beans.BeanUtils;
import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.common.constants.bank.CmbConstants;
import com.gopay.common.domain.bank.BcdlMessage;
import com.gopay.common.domain.bank.cmb.bcdl.CmbBcdlMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.businesses.BcdlService;

public class CmbBcdlManager {
	@Resource(name = "cmbBcdlService")
	private BcdlService cmbBcdlService;
	@Resource(name = "cmbConfig")
	private Map<String, String> cmbConfig;

	public Object eft(BcdlMessage msg) throws GopayException {
		CmbBcdlMessage msgSnd =buildMessage(msg);
		BankLogUtils.printBcdlEftManagerSendLog(msgSnd);
		CmbBcdlMessage resMsg=(CmbBcdlMessage)cmbBcdlService.eft(msgSnd);
		BankLogUtils.printBcdlEftManagerReturnLog(msgSnd);
		return resMsg;
	}

	private CmbBcdlMessage buildMessage(BcdlMessage msg) {
		CmbBcdlMessage cmbMsg= new CmbBcdlMessage();
		BeanUtils.copyProperties(msg, cmbMsg);
		cmbMsg.setLoginName(cmbConfig.get("CMB.BCDL.LOGNAM"));
		cmbMsg.setRemark(msg.getGopayBankOrderNo());
		if(msg.getSysIOFlg()==0){
			cmbMsg.setBnkflg(CmbConstants.BNKFLG_Y);	
		}else{
			cmbMsg.setBnkflg(CmbConstants.BNKFLG_N);
		}
		return cmbMsg;
	}
	
	public Object query(Object obj) throws GopayException {
		BcdlMessage msg = (BcdlMessage) obj;
		CmbBcdlMessage msgSnd = buildQueryMessage(msg);
		BankLogUtils.printBcdlManagerQuerySendLog(msgSnd);
		CmbBcdlMessage o=(CmbBcdlMessage)cmbBcdlService.query(msgSnd);
		BankLogUtils.printBcdlManagerQueryReturnLog(msgSnd);
		return o;
	}
	
    public Object queryBalance(Object obj) throws GopayException {
        BcdlMessage msg = (BcdlMessage) obj;
        CmbBcdlMessage msgSnd = new CmbBcdlMessage();
        BeanUtils.copyProperties(msg, msgSnd);
        msgSnd.setLoginName(cmbConfig.get("CMB.BCDL.LOGNAM"));
        BankLogUtils.printBcdlManagerQueryBalanceSendLog(msgSnd);
        CmbBcdlMessage o = (CmbBcdlMessage) cmbBcdlService.queryBalance(msgSnd);
        BankLogUtils.printBcdlManagerQueryBalanceReturnLog(msgSnd);
        return o;
    }

	private CmbBcdlMessage buildQueryMessage(BcdlMessage msg) {
		CmbBcdlMessage cmbMsg= new CmbBcdlMessage();
		BeanUtils.copyProperties(msg, cmbMsg);
		cmbMsg.setLoginName(cmbConfig.get("CMB.BCDL.LOGNAM"));
		return cmbMsg;
	}

	public Object queryAcctDetail(Object obj) throws GopayException {
        CmbBcdlMessage mags=(CmbBcdlMessage)obj;
        CmbDownLoadMessage msg=(CmbDownLoadMessage)obj;
        String msgDOwnLoad=msg.getHost()+"/"+ msg.getSender()+"/"+ msg.getUsername()+"/"+msg.getPassword()+"/"+msg.getReceiver()+"/"+msg.getCc()+"/"+msg.getDateTypes()+"/"+msg.getQuerySize();
        CmbBcdlMessage msgSnd = new CmbBcdlMessage();
        msgSnd.setRemark(msgDOwnLoad);
        msgSnd.setOrderDate(msg.getOrderDate());
        msgSnd.setLoginName(cmbConfig.get("CMB.BCDL.LOGNAM"));
        CmbBcdlMessage o = (CmbBcdlMessage) cmbBcdlService.queryAcctDetail(msgSnd);
        return o;
    }


}